
#region Using

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using WebLibs;

#endregion
namespace FEAT.Library
{
    /// <summary>
	/// Created by 		: Phan Hữu Hưng 
	/// Created date 	: 25/03/2010 
	/// Description 
	/// </summary>	
	public class ShareUserPicture
	{
	
		
	
		#region Member Variables

		private int intPictureID = int.MinValue;
		private string strPictureName = string.Empty;
		private string strPicturePath = string.Empty;
		private string strDescription = string.Empty;
		private bool bolIsShareAll;
		private int intViewTimes = int.MinValue;
		private IData objDataAccess = null;


		#endregion


		#region Properties 

		public static string CacheKey
		{
  			get { return  "ShareUserPicture_GetAll";}
		}
		/// <summary>
		/// Đối tượng Data truyền từ ngoài vào
		/// </summary>
		public IData DataObject
		{
  			get { return objDataAccess; }
   			set { objDataAccess = value; }
		}
		/// <summary>
		/// PictureID
		/// 
		/// </summary>
		public int PictureID
		{
			get { return  intPictureID; }
			set { intPictureID = value; }
		}

		/// <summary>
		/// PictureName
		/// 
		/// </summary>
		public string PictureName
		{
			get { return  strPictureName; }
			set { strPictureName = value; }
		}

		/// <summary>
		/// PicturePath
		/// 
		/// </summary>
		public string PicturePath
		{
			get { return  strPicturePath; }
			set { strPicturePath = value; }
		}

		/// <summary>
		/// Description
		/// 
		/// </summary>
		public string Description
		{
			get { return  strDescription; }
			set { strDescription = value; }
		}

		/// <summary>
		/// IsShareAll
		/// 
		/// </summary>
		public bool IsShareAll
		{
			get { return  bolIsShareAll; }
			set { bolIsShareAll = value; }
		}

		/// <summary>
		/// ViewTimes
		/// 
		/// </summary>
		public int ViewTimes
		{
			get { return  intViewTimes; }
			set { intViewTimes = value; }
		}


		#endregion		
		
		
		#region Constructor

		public ShareUserPicture()
		{
		}
		private static ShareUserPicture _current;
		static ShareUserPicture()
		{
			_current = new ShareUserPicture();
		}
		public static ShareUserPicture Current
		{
			get
			{
		      return _current;
			}
		}
		#endregion

		#region Methods	



		///<summary>
		/// Kiểm tra xem đối tượng có dữ liệu hay không
		///</summary>
		/// <returns>true ? Có : False ? Không</returns>
		public bool LoadByPrimaryKeys()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			bool bolOK = false;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Share_UserPicture_Select");
				objData.AddParameter("@PictureID", this.PictureID);
				IDataReader reader = objData.ExecStoreToDataReader();
				if (reader.Read())
 				{
					if(!this.IsDBNull(reader["PictureID"]))	this.PictureID = Convert.ToInt32(reader["PictureID"]);
					if(!this.IsDBNull(reader["PictureName"]))	this.PictureName = Convert.ToString(reader["PictureName"]);
					if(!this.IsDBNull(reader["PicturePath"]))	this.PicturePath = Convert.ToString(reader["PicturePath"]);
					if(!this.IsDBNull(reader["Description"]))	this.Description = Convert.ToString(reader["Description"]);
					if(!this.IsDBNull(reader["IsShareAll"]))	this.IsShareAll = Convert.ToBoolean(reader["IsShareAll"]);
					if(!this.IsDBNull(reader["ViewTimes"]))	this.ViewTimes = Convert.ToInt32(reader["ViewTimes"]);
 					bolOK = true;
 				}
				reader.Close();
			}
			catch (Exception objEx)
			{
				throw new Exception("LoadByPrimaryKeys() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return bolOK;
		}

		///<summary>
		/// Insert : Share_UserPicture
		/// Them moi du lieu
		///</summary>
		public object Insert()
		{
			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			object objTemp = null;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Share_UserPicture_Insert");
				if(this.PictureID != int.MinValue) objData.AddParameter("@PictureID", this.PictureID);
				objData.AddParameter("@PictureName", this.PictureName);
				objData.AddParameter("@PicturePath", this.PicturePath);
				objData.AddParameter("@Description", this.Description);
				objData.AddParameter("@IsShareAll", this.IsShareAll);
				if(this.ViewTimes != int.MinValue) objData.AddParameter("@ViewTimes", this.ViewTimes);
                objTemp = objData.ExecStoreToString();
			}
			catch (Exception objEx)
			{
				throw new Exception("Insert() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return objTemp;
		}


		///<summary>
		/// Update : Share_UserPicture
		/// Cap nhap thong tin
		///</summary>
		public object Update()
		{
			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			object objTemp = null;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Share_UserPicture_Update");
				if(this.PictureID != int.MinValue)	objData.AddParameter("@PictureID", this.PictureID);
				else objData.AddParameter("@PictureID", DBNull.Value);
				objData.AddParameter("@PictureName", this.PictureName);
				objData.AddParameter("@PicturePath", this.PicturePath);
				objData.AddParameter("@Description", this.Description);
				objData.AddParameter("@IsShareAll", this.IsShareAll);
				if(this.ViewTimes != int.MinValue)	objData.AddParameter("@ViewTimes", this.ViewTimes);
				else objData.AddParameter("@ViewTimes", DBNull.Value);
                objTemp = objData.ExecNonQuery();
			}
			catch (Exception objEx)
			{
				throw new Exception("Update() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return objTemp;
		}


		///<summary>
		/// Delete : Share_UserPicture
		///
		///</summary>
		public int Delete()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			int intTemp = 0;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Share_UserPicture_Delete");
				objData.AddParameter("@PictureID", this.PictureID);
 				intTemp = objData.ExecNonQuery();
			}
			catch (Exception objEx)
			{
				throw new Exception("Delete() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return intTemp;
		}


		///<summary>
		/// Get all : Share_UserPicture
		///
		///</summary>
		public DataTable GetAll()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			try
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Share_UserPicture_SelectAll");
				return objData.ExecStoreToDataTable();
			}
			catch (Exception objEx)
			{
				throw new Exception("GetAll() Error   " + objEx.Message.ToString());
			}
			finally
			{
    		 if (objDataAccess == null)
        		objData.DeConnect();
			}
		}
		#endregion


		/// <summary>
        /// Check Data IsDBNull 
        /// </summary>
        /// <param name="objObject"> Object Value</param>
        /// <returns>Null : true ? false </returns>
		private bool IsDBNull(object objObject)
		{
			return Convert.IsDBNull(objObject);
		}
		
		
		/******************************************************
		 	Share_UserPicture objShare_UserPicture = new Share_UserPicture();
			objShareUserPicture.PictureID = txtPictureID.Text;
			objShareUserPicture.PictureName = txtPictureName.Text;
			objShareUserPicture.PicturePath = txtPicturePath.Text;
			objShareUserPicture.Description = txtDescription.Text;
			objShareUserPicture.IsShareAll = txtIsShareAll.Text;
			objShareUserPicture.ViewTimes = txtViewTimes.Text;

		 
		 ******************************************************
		 
		 			txtPictureID.Text = objShareUserPicture.PictureID;
			txtPictureName.Text = objShareUserPicture.PictureName;
			txtPicturePath.Text = objShareUserPicture.PicturePath;
			txtDescription.Text = objShareUserPicture.Description;
			txtIsShareAll.Text = objShareUserPicture.IsShareAll;
			txtViewTimes.Text = objShareUserPicture.ViewTimes;

		 
		*******************************************************/
		
	}
}
